//
// Created by test on 23-3-4.
//
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
#include<stdio.h>
#include<iostream>
#include<sys/stat.h>
#include<sys/fcntl.h>
#include<sys/uio.h>
#include<cstdlib>
#include<sys/sendfile.h>
int main(int argc,char* argv[]){
    const char* ip=argv[1];
    int port=atoi(argv[2]);
    sockaddr_in addr;
    addr.sin_family=AF_INET;
    addr.sin_port=htons(port);
    inet_pton(AF_INET,ip,&addr.sin_addr);
    int sock=socket(PF_INET,SOCK_STREAM,0);
    int ret=bind(sock,(struct sockaddr*)&addr,sizeof(addr));
    assert(ret!=-1);
    ret=listen(sock,5);
    struct sockaddr_in client;
    socklen_t client_len=sizeof(client);
    int connfd=accept(sock,(struct sockaddr*)&client,&client_len);
    assert(connfd>=0);
    int pipefd[2];
    ret=pipe(pipefd);
    ret=splice(connfd,NULL,pipefd[1],NULL,32768,SPLICE_F_MORE|SPLICE_F_MOVE);
    ret=splice(pipefd[0],NULL,connfd,NULL,32768,SPLICE_F_MORE|SPLICE_F_MOVE);
    close(connfd);
    close(sock);
    return 0;
}